Skip to content

fix(runtime): guard Windows bundled runtime arch detection#94

Merged
zouyonghe merged 2 commits intoAstrBotDevs:mainfrom
zouyonghe:fix/windows-runtime-arch-guard
Mar 14, 2026
Merged

fix(runtime): guard Windows bundled runtime arch detection#94
zouyonghe merged 2 commits intoAstrBotDevs:mainfrom
zouyonghe:fix/windows-runtime-arch-guard

Conversation

@zouyonghe
Copy link
Member

@zouyonghe zouyonghe commented Mar 14, 2026

Summary

  • make isWindowsArm64BundledRuntime return false instead of throwing when it runs on win32 with an unsupported host process.arch and no explicit arch override
  • keep explicit bundled-runtime and target-arch overrides working by only short-circuiting the unsupported-host fallback case
  • add a regression test covering the unsupported Windows host arch path

Test Plan

  • node --test scripts/backend/runtime-arch-utils.test.mjs
  • pnpm run test:prepare-resources

Summary by Sourcery

Guard Windows bundled runtime architecture detection against unsupported host architectures and centralize runtime-arch override handling.

Bug Fixes:

  • Make Windows ARM64 bundled runtime detection return false instead of erroring when running on win32 with an unsupported host architecture and no override.

Enhancements:

  • Introduce shared helpers to detect non-empty runtime architecture override environment variables and reuse them in runtime arch resolution logic.

Tests:

  • Add regression tests for unsupported Windows host architectures and for runtime-arch override environment variable handling.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of the runtime architecture detection logic on Windows. It prevents errors when the system encounters an unsupported host architecture by implementing guard clauses, while ensuring that explicit architecture overrides remain fully functional. This change improves the stability and predictability of the application's runtime environment setup.

Highlights

  • Runtime Architecture Detection: The isWindowsArm64BundledRuntime function now gracefully handles unsupported Windows host architectures by returning false instead of throwing an error, specifically when no explicit architecture overrides are provided.
  • Override Preservation: Explicit bundled-runtime and target-arch overrides continue to function as intended, ensuring that manual configurations are respected.
  • Test Coverage: A new regression test was added to validate the behavior of isWindowsArm64BundledRuntime when encountering unsupported Windows host architectures.
Changelog
  • scripts/backend/runtime-arch-utils.mjs
    • Modified the isWindowsArm64BundledRuntime function to include early exit conditions for non-Windows platforms and unsupported Windows host architectures without explicit overrides.
  • scripts/backend/runtime-arch-utils.test.mjs
    • Added a new test case to verify that isWindowsArm64BundledRuntime returns false for unsupported Windows host architectures.
Activity
  • The author has confirmed the test plan by running node --test scripts/backend/runtime-arch-utils.test.mjs and pnpm run test:prepare-resources.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The hasBundledRuntimeOverride / hasTargetArchOverride variables currently hold string values; consider explicitly coercing them to booleans (e.g. Boolean(String(...).trim())) so their types better match the naming and avoid accidental truthiness issues if the logic is reused.
  • The override-detection logic added in isWindowsArm64BundledRuntime is somewhat verbose; consider extracting a small helper (e.g. hasRuntimeArchOverride(env)) to keep this function focused on its main decision and make future changes to the override rules easier.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `hasBundledRuntimeOverride` / `hasTargetArchOverride` variables currently hold string values; consider explicitly coercing them to booleans (e.g. `Boolean(String(...).trim())`) so their types better match the naming and avoid accidental truthiness issues if the logic is reused.
- The override-detection logic added in `isWindowsArm64BundledRuntime` is somewhat verbose; consider extracting a small helper (e.g. `hasRuntimeArchOverride(env)`) to keep this function focused on its main decision and make future changes to the override rules easier.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses a potential crash in isWindowsArm64BundledRuntime when running on an unsupported host architecture without explicit overrides. The fix correctly introduces a guard to return false in this scenario, and the new regression test properly covers this case. I have one suggestion to improve the readability of the new logic by reducing code duplication.

Comment on lines +69 to +72
const hasBundledRuntimeOverride =
env[BUNDLED_RUNTIME_ARCH_ENV] !== undefined && String(env[BUNDLED_RUNTIME_ARCH_ENV]).trim();
const hasTargetArchOverride =
env[DESKTOP_TARGET_ARCH_ENV] !== undefined && String(env[DESKTOP_TARGET_ARCH_ENV]).trim();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve readability and reduce code duplication, you could extract the repeated logic for checking if an environment variable is set to a non-empty string into a small helper function within the scope of this function.

Suggested change
const hasBundledRuntimeOverride =
env[BUNDLED_RUNTIME_ARCH_ENV] !== undefined && String(env[BUNDLED_RUNTIME_ARCH_ENV]).trim();
const hasTargetArchOverride =
env[DESKTOP_TARGET_ARCH_ENV] !== undefined && String(env[DESKTOP_TARGET_ARCH_ENV]).trim();
const isSet = (v) => v !== undefined && String(v).trim();
const hasBundledRuntimeOverride = isSet(env[BUNDLED_RUNTIME_ARCH_ENV]);
const hasTargetArchOverride = isSet(env[DESKTOP_TARGET_ARCH_ENV]);

@zouyonghe
Copy link
Member Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@zouyonghe zouyonghe merged commit eeb2ebf into AstrBotDevs:main Mar 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant